(function () { "use strict"; var cfg = window.travelgoThemeWidgets || {}; var isMobile = window.matchMedia("(max-width: 767px)").matches; function canShowDevice(mobile, desktop) { if (isMobile) return !!mobile; return !!desktop; } function randomOf(arr, fallback) { if (!Array.isArray(arr) || arr.length === 0) return fallback; return arr[Math.floor(Math.random() * arr.length)]; } function buildSalesMessage() { var name = randomOf(cfg.salesNames, "A customer"); var item = randomOf(cfg.salesItems, "booked a trip"); var place = randomOf(cfg.salesLocations, "just now"); var mins = randomOf([5, 7, 10, 12, 15], 10); return name + " from " + place + " " + item + " " + mins + " min ago"; } function renderSalesPopup() { if (!cfg.salesEnabled || !canShowDevice(cfg.salesMobile, cfg.salesDesktop)) return; var node = document.createElement("div"); node.className = "travelgo-sales-popup"; node.innerHTML = '
' + '' + ''; node.querySelector(".travelgo-sales-popup__text").textContent = buildSalesMessage(); document.body.appendChild(node); var close = node.querySelector(".travelgo-sales-popup__close"); close.addEventListener("click", function () { node.remove(); }); setTimeout(function () { node.classList.add("is-open"); }, 100); setTimeout(function () { node.classList.remove("is-open"); setTimeout(function () { node.remove(); }, 300); }, 5200); } function initSalesLoop() { if (!cfg.salesEnabled || !canShowDevice(cfg.salesMobile, cfg.salesDesktop)) return; var interval = Math.max(parseInt(cfg.salesInterval || 12, 10), 5) * 1000; setTimeout(renderSalesPopup, 2000); setInterval(renderSalesPopup, interval); } function initWhatsApp() { if (!cfg.whatsappEnabled || !cfg.whatsappNumber || !canShowDevice(cfg.whatsappMobile, cfg.whatsappDesktop)) return; var msg = encodeURIComponent(cfg.whatsappMessage || "Hi! I need help."); var href = "https://wa.me/" + cfg.whatsappNumber + "?text=" + msg; var label = cfg.whatsappLabel || "Chat with us"; var a = document.createElement("a"); a.className = "travelgo-whatsapp-widget"; a.href = href; a.target = "_blank"; a.rel = "noopener noreferrer"; a.innerHTML = '' + ''; a.querySelector(".travelgo-whatsapp-widget__label").textContent = label; document.body.appendChild(a); } document.addEventListener("DOMContentLoaded", function () { initWhatsApp(); initSalesLoop(); }); })();